package com.teamwhole.modules.grid.web;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.teamwhole.common.model.ResultInfo;
import com.teamwhole.modules.grid.entity.Grid;
import com.teamwhole.modules.grid.service.GridService;

@Component
@Path("/gcb/grid")
@Consumes("application/json;charset=utf-8")
@Produces("application/json;charset=utf-8")
public class GridResource {
	
	@Autowired
	private GridService gridService;
	
	//在列表中显示所有广场,pid为0的时候(不含有区域)
	@Path("/findList")
	@POST
	public List<Grid> findByLoginName(Grid model) {
		return gridService.findList(model);
	}
	
	//返回区域(PID非0)
	@Path("/findRegionList")
	@POST
	public List<Grid> findByName(Grid model) {
		return gridService.findRegionList(model);
	}
	
	
	//返回单个广场
	@Path("/findSingleGrid")
	@POST
	public List<Grid> findById(Grid model) {
		return gridService.findSingleGrid(model);
	}
	
	//返回一个
	@Path("/get")
	@GET
	public Grid get(@QueryParam("id") String id) {
		return gridService.get(id);
	}
	
	//增加一个 
	@Path("/create")
	@POST
	public ResultInfo create(Grid model) {
		gridService.save(model);
		return ResultInfo.ok();
	}
	
	//更新
	@Path("/update")
	@POST
	public ResultInfo update(Grid model) {
		gridService.save(model);
		return ResultInfo.ok();
	}
	
	//删除
	@Path("/delete")
	@GET
	public ResultInfo delete(@QueryParam("id") String id) {
		gridService.delete(id);
		return ResultInfo.ok();
	}
	
	@Path("/findListByPid")
	@GET
	public List<Grid> findListByPid(@QueryParam("id") String id) {
		return gridService.findListByPid(id);
	}
	
	@Path("/findRegions")
	@POST
	public List<Grid> findRegions(Grid model) {
		if(model == null){
			return null;
		}
		return gridService.findRegionList(model);
	}
	
	@Path("/findRegionById")
	@GET
	public List<Grid> findRegionById(@QueryParam("id") String id) {
		Grid model = new Grid();
		model.setId(id);
		model.setPid("0");
		return gridService.findRegionList(model);
	}
}
